//
//  CustomTwoTableViewCell.m
//  10-tableViewCell-custom
//
//  Created by 王道林 on 16/7/27.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "CustomTwoTableViewCell.h"
// 使用@class声明的类, 需要在.m中去import
#import "NewsObject.h"
@implementation CustomTwoTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
   self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubview];
    }
    return self;
}

- (void)createSubview
{
    _iamgeView = [[UIImageView alloc] init];
    [self.contentView addSubview:_iamgeView];
    _lableTitle = [[UILabel alloc] init];
    
    _lableTitle.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:_lableTitle];
    
    _lableCont = [[UILabel alloc] init];

    _lableCont.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:_lableCont];
    
    _lablePer = [[UILabel alloc] init];
    _lablePer.backgroundColor = [UIColor blueColor];
    [_lableCont addSubview:_lablePer];
    
}

// 有内容/ 坐标改变时候, 触发layoutsubview
- (void)layoutSubviews
{
    [super layoutSubviews];
    _iamgeView.frame = CGRectMake(0, 0, 200, self.contentView.frame.size.height);
    _lableTitle.frame = CGRectMake(200, 0, self.contentView.frame.size.width - 200, 80);
    _lableCont.frame = CGRectMake(200, 100, self.contentView.frame.size.width - 200, 100);
    _lablePer.frame = CGRectMake(100, 60, self.contentView.frame.size.width - 300, 40);
    // 改变_lablePer的父视图.. 防止视图位置改变
    [_lableCont addSubview:_lablePer];
    
    // 视图坐标系转化
   CGRect rect = [_lablePer.superview convertRect:_lablePer.frame toView:self.contentView];
    _lablePer.frame = rect;
    [self.contentView addSubview:_lablePer];
    
}

-(void)setNewsObject:(NewsObject *)newsObject
{
    _newsObject = newsObject;
    _iamgeView.image = [UIImage imageNamed:_newsObject.newsImage];
    _lableTitle.text = _newsObject.newsTitle;
    _lableCont.text = _newsObject.newsDescription;
    _lablePer.text = _newsObject.newsNumber;
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
